//
// Created by buyongjiu on 2024/4/21.
//

#ifndef FEI_LAXER_DFA_H
#define FEI_LAXER_DFA_H

#include <string>
#include <map>
#include <set>
#include <assert.h>

#include "NFA.h"

struct DFA_struct{
    Type_t type;
    std::string nowState;
    std::map<std::string, std::string> gotoState;
    DFA_struct(Type_t t, std::string nowstate);
    int addEdge(std::string &input, std::string &next);
};

class DFA {
    std::map<std::string, DFA_struct*> nameToStruct;
    std::set<std::string> alphabet;
    std::vector<DFA_struct *> Structs;
    std::set<std::string> state;
    std::set<NFA_struct *> move_(NFA &nfa, std::set<NFA_struct *> cur, std::string input);
    int closure_(NFA &nfa, std::set<NFA_struct *> &cur);
    std::string subSetsTostr(const std::set<NFA_struct *>& subSets);
    std::set<NFA_struct *> strTosubSets(NFA &nfa, std::string str);

public:
    int createDFA(NFA &nfa);
    void PrintDFA();
    bool accept(std::string str);
};


#endif //FEI_LAXER_DFA_H
